layui.use([ 'form'], function() {
    var form = layui.form;
    let $ = layui.$;
    //监听提交
    form.on('submit(formDemo)', function(data){
        if(!data.field.status) {
            data.field.status = '1';
        }
        if(!data.field.platformId) {
            data.field.platformId = getTokenInfo().platformId;
        }
        if(data.field.apiUrl != '') {
            // url需要添加平台名称才能正确授权访问
            data.field.apiUrl = '/' + getTokenInfo().platformName + data.field.apiUrl
        }
        $.ajax({
            dataType: 'json',
            type: 'post',
            contentType: 'application/json;charset=UTF-8',
            data: JSON.stringify(data.field),
            url: Api.uaa.menu.menu,
            success: function (result, status, xhr) {
                if(result.code == 200) {
                    window.location = 'index.html'
                } else {
                    layer.alert(result.msg)
                }

            },
            error: function(xhr, status, error) {
                console.log(xhr);
                // layer.alert(error)
            }
        })
        return false;
    });


})
